<template>
    <div>
        <!-- 导航 -->
        <van-nav-bar title="搜索" left-text="返回" left-arrow @click-left="() => { $router.push('/index/sy') }" />

        <!-- 搜索 -->
        <van-search v-model="value" shape="round" placeholder="请输入搜索关键词" />

        <!-- 单元格 -->
        <van-cell-group v-for="item in qsearch">
            <router-link :to="'/xq/' + item.goods_id">
                <van-cell :title="item.goods_name" />
            </router-link>
        </van-cell-group>

        <!-- 空状态 -->
        <van-empty image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png" image-size="80"
            description="描述文字" />
    </div>
</template>

<script setup>
import { ref, watch } from 'vue';
import { qsearchApi } from '@/api/api';
import _ from 'lodash'
let sta = ref(false)
let value = ref('')
let qsearch = ref([])
watch(value,
    _.debounce((val) => {
        qsearchApi(val).then(res => {
            console.log('搜索数据', res)
            qsearch.value = res.data.message
            if (res.data.code == 0) {
                sta.value = true
            }
            else {
                sta.value = false
            }
        })
    }, 2000)
)

</script>

<style lang="scss" scoped></style>